<template>
	<view class="page">
		<uni-forms ref="baseForm" label-position="top" :modelValue="baseFormData">
			<uni-forms-item label="ID" name="id">
				<uni-easyinput type="number" v-model="baseFormData.id" placeholder="请输入用户ID" />
			</uni-forms-item>
			<uni-forms-item label="手机号" name="mobile">
				<uni-easyinput type="number" v-model="baseFormData.mobile" placeholder="请输入用户手机号" />
			</uni-forms-item>
			<button class="fbt" @click="submit('baseForm')">切换</button>
			<!-- 输入框示例 -->
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="inputClose" before-close="true" mode="input" title="输入权限密码" :value="baseFormData.pwd" placeholder="请输入权限密码" @confirm="dialogInputConfirm" @close="closeDialog"></uni-popup-dialog>
			</uni-popup>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseFormData: {
					id: '',
					mobile: '',
				},
				// rules: {
				// 	id: {
				// 		rules: [{
				// 			required: true,
				// 			errorMessage: '请输入ID',
				// 		}]
				// 	},
				// 	mobile: {
				// 		rules: [{
				// 			required: true,
				// 			errorMessage: '请输入手机号',
				// 		}]
				// 	},
				// }
			};
		},
		onReady() {
			this.$refs.baseForm.setRules(this.rules)
		},
		methods: {
			submit(ref) {
				this.$refs[ref].validate().then(res=>{
					if(this.baseFormData.id!=''||this.baseFormData.mobile!=''){
						this.$refs.inputDialog.open()
					}else{
						this.$api.msg('请输入ID或者手机号');
					}
				})
			},
			dialogInputConfirm(value){
				if(value=='') return this.$api.msg('请输入权限密码');
				this.$axios('login/changeUser','POST','member',{
					id: this.baseFormData.id,
					mobile: this.baseFormData.mobile,
					pwd: value
				}).then(res=>{
					if(res.data.code == 200){
						uni.setStorageSync('token', res.data.data);
						uni.setStorageSync('Jh_recotabshops', 1);
						this.$refs.inputDialog.close();
						uni.switchTab({
							url: '/pages/individualism/user'
						});
					}
				})
			},
			closeDialog(){
				this.$refs.inputDialog.close();
			}
		}
	}
</script>

<style lang="scss">
.page{
	padding: 30rpx;
}
.fbt{
	margin-top: 90rpx;
	line-height: 2.5;
	border-radius: 15rpx;
}
</style>
